// *** SOUND OBJECT *** //
// Controls the sounds on the site
//
// @project: GoldenShield
// @author: Kasper B. Jensen
// @version: 1.0

var sound = {
    
    //Initialize the function and adds a sound object to the scne
    init: function() {
        $("#sounds").append("<audio id='swordSound' src='sounds/sword.mp3' preload></source>");
        $("#sounds").append("<audio id='walk' src='sounds/walkFast.mp3' preload></source>");
    },
    
    play: function(sound, vol) {
      if(sound != null) {
          var sound = document.getElementById(sound);
          if(sound != null && !sound.playing) {
              if(vol > 0) {
                  //sound.volume = vol;
              }
              
            sound.play();
          }
      }  
    },
    
    playSoundByObjectID: function(id) {
        if(id) {
            var soundID = $('.' + id).attr('id');
            sound.play(soundID);
            console.log(soundID);
        }
    },
    
    playBgSound: function() {
        var id = $('.mapBgSound ').attr('id');
        if(id) {
            $('#' + id).attr('loop', true);
            sound.play(id, 2);
        }
    },
    
    
    setSurfaceSound: function(id) {
      if(id) {
          $('.surfaceSound').each(function() {
              if($(this).hasClass(id)) {
                  var soundID = $(this).attr("id");
                  player.surfaceSound = soundID;
              }
          })
      }  
    }
}